// 生成邀请链接
import request from "@/api/request.js";
import {useStore} from "@/stores/store.js";
import {ElMessage} from "element-plus";

export function generateInviteInfo(data) {
    return request({
        url: '/music/together/generate_invite',
        method: 'post',
        data: data
    })
}

export function createTogetherRoom() {
    ElMessage.success('她曾经来过')
    // if (useStore().togetherRoomInfo.togetherRoomId != null) return
    // 只有房间号没有的时候，才能创建
    return request({
        url: '/music/together/create_room',
        method: 'post',
        data: {inviterAccount: localStorage.getItem('account')}
    }).then((res) => {
        console.log(res)
        useStore().togetherRoomInfo.togetherRoomId = res.data
    })
}

export function getInviteInfoByRoomId(roomId) {
    // 只有房间号没有的时候，才能创建
    return request({
        url: '/music/together/invite_info?roomId=' + roomId ,
        method: 'get',
    })
}

export function acceptInvite(roomId, inviteeAccount) {
    // 只有房间号没有的时候，才能创建
    return request({
        url: '/music/together/accept_invite' ,
        method: 'post',
        data: { roomId: roomId, inviteeAccount: inviteeAccount}
    })
}

export function getOwnerSheet(roomId, sheetId) {
    if (roomId == null) roomId = ''
    if (sheetId == null) sheetId = ''
    console.log(2)
    return request({
        url: '/music/together/sheet_musicList?roomId=' + roomId + '&sheetId=' + sheetId ,
        method: 'get'
    })
}

export function getMyIdentity(roomId, account) {
    return request({
        url: `/music/together/identity?roomId=${roomId}&account=${account}` ,
        method: 'get'
    })
}
export function getOwnerInfo(roomId) {
    return request({
        url: '/music/together/ownerInfo?roomId=' + roomId,
        method: 'get'
    })
}
export function getVisitorInfo(roomId) {
    return request({
        url: '/music/together/visitorInfo?roomId=' + roomId,
        method: 'get'
    })
}
